/**
 * Copyright (C), 2018 store
 * Encoding: UTF-8
 * Date: 19-10-25 上午10:51
 * History:
 */
package com.swak.frame.dto.base;

import java.util.Objects;

/**
 * RestApiCode.java
 * 
 * @author ColleyMa
 * @version 19-10-25 上午10:51
 */
public interface RestApiCode {

    static final String REGEX = "([a-z])([A-Z])";

    public String getRetCode();

    public String getRetMessage();

    public String getRetDesc();

    default public boolean eq(String retCode) {
        return Objects.equals(retCode, this.getRetCode());
    }

    default public String getResource() {
        String resource = null;
        if (this instanceof Enum<?>) {
            Enum<?> thizEnum = (Enum<?>) this;
            resource = thizEnum.name() + "_" + this.getRetCode();
        } else {
            resource = this.getClass().getSimpleName() + "_" + getRetCode();
        }
        return resource.replaceAll(REGEX, "$1_$2").toLowerCase();
    }
}
